<?php

	/**
	 * Pop up templates
	 * Just load the classes / helpers etc that would be needed to run modules without 
	 * any formatting etc
	 */

	if ( USE_GZHANDLER )
	{
		ob_start("ob_gzhandler");
	}

	/**
	 * Include HTML template specific interfaces
	 */

	if ( ! class_exists('image_read') )
	{
		include "interfaces/image_read.inc";
	}

	if ( ! class_exists('Pager') )
	{
		include_once "{$TARGET->template_root}/html_helpers.inc";
	}


?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title><?php echo $TARGET->page_title; ?></title>

<?php


	
print <<<END
<script src="{$SITE_ROOT}{$TARGET->template_root}/js/common.js" type="text/javascript"></script>
	<script type="text/javascript" src="{$SITE_ROOT}third_party/jquery/jquery.js"></script>
	 <script type="text/javascript">
	 	// put jquery here
	 </script>
END;

print <<<END
<style type="text/css">

	@import url("{$SITE_ROOT}{$TARGET->template_root}/css/common.css");
</style>
	<link rel="shortcut icon" href="{$SITE_ROOT}{$TARGET->template_root}/gfx/favicon.ico" />\n
END;

	/**
	 * In some special cases we have extra CSS stored in the actions dir.
	 */

	if ( $TARGET->css != 'none' )
	{

print <<<END
	<link rel="stylesheet" href="{$SITE_ROOT}$TARGET->css" />\n
END;

	}

?>

</head>
<body>
	<div id="iframe_panel">
		<?php
		
			$h1 = '';
			if ( $TARGET->use_h1 )
			{
				$h1 = "<h1>{$TARGET->content_title}</h1>\n";
			}
			
			if ( $TARGET->htm_content != 'none' && $TARGET->htm_content )
			{
				echo $h1;
				echo $TARGET->htm_content;
			}
			else if ( $TARGET->htm_file != 'none' && file_exists($TARGET->htm_file) )
			{
				if ( isset($TARGET->no_h1_tags) )
				{
					echo $h1;
				}
				include $TARGET->htm_file;
			}
			else
			{
				echo $h1;
				echo "<p>No page not found ~ <b>{$TARGET->action}</b></p>";
			}
			
			// Just for localhost debug
			if ( defined('DEBUG') && DEBUG == true )
			{
		
				/**
				 * Write debug data to special HTML file based on user session ID
				 * (if debug is set to true)
				 *
				 * @todo Requires config option to set which environments this should run on
				 */
		
				include_once "lib/debug.inc";
				$debug = new debug;
				file_write(DATA_DIR."/trace/".preg_replace('/\//','.FS.',$TARGET->action_orig).'.htm',$debug->display());
		
				// Print out debug stuff
				if ( $trace_files = dir_to_array(DATA_DIR.'/trace') )
				{
					print "<h2>View trace file for recent action</h2><ul>";	
			
					foreach ( dir_to_array(DATA_DIR.'/trace') as $trace_file )
					{
						print "<li><a href=\"{$SITE_ROOT}{$TARGET->data_dir}/trace/$trace_file\" target=\"_blank\"><b>".str_replace('.FS.','/',str_replace('.htm','',$trace_file))."</b></a></li>";
					}
			
					print "</ul>";
				}
		
				print_ar($_SESSION);
				print_ar($TARGET);
				print_ar($_COOKIE);
			}
		?>
		<br/><br/>
	</div>
</body>
</html>